﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ctManagementIntroduce.ascx.cs" Inherits="KhoaLuan.MainSys.Manager.Controls.ctManagementIntroduce" %>
<link href="/Style/StyleCommon.css" rel="stylesheet" />
<link href="/Style/modal.css" rel="stylesheet" />
<script src="/Scripts/dluscript.js"></script>
<script type="text/javascript">

    function LoadListIntro(totalitem, target, listIntro) {
        debugger;
        target.empty();
        listIntro.forEach(function (item) {
            var tr = $("<tr>");
            var td = $("<td>").append(Common.CreateCheckBox(item.IntroduceId));
            tr.append(td);
            td = $("<td>").text(item.Title);
            tr.append(td);
            td = $("<td>");
            var btnedit = CreateButton(item.IntroduceId, "fa-edit");
            debugger;
            btnedit.click(function () {
                location.href = "/MainSys/Manager/Introduces/AddNewIntro.aspx?IntroID=" + $(this).attr('dataid');
            });
            td.append(btnedit);

            var btndel = CreateButton(item.IntroduceId, "fa-times");
            btndel.click(function () {
                debugger;
                var id = $(this).attr("dataid");
                var sender = $(this);
                confirm("Xác nhận", "Bạn có muốn xóa bài này không", "Xóa", "Hủy bỏ", function () {
                    debugger;
                    CallAjaxAspx("POST", "DeleteUser", "/MainSys/ProcessAJAX/AjaxUser.aspx", { Id: parseInt(id) }, function (data) {
                        debugger;
                        var responseDel = JSON.parse(data);

                        if (responseDel.Status) {
                            debugger;
                            sender.parent().parent().remove();
                            alertSmallBox("Xóa bài viết thành công", "1 giây trước...");
                        }
                        else {
                            alertSmallBox("Xóa bài viết thất bại", "1 giây trước...", "error");
                        }
                    }, function () { }, function () { });
                });
            });
            debugger;
            td.append(btndel);
            var btnview = CreateButton(item.IntroduceId, "fa-eye");
            btnview.attr("OrgID", item.OrgID)
            btnview.click(function () {
                window.open('/MainSys/IntroduceDepPage.aspx?IntroID=' + $(this).attr("dataid") + "&OrgID=" + $(this).attr("OrgID"), "_blank");
            });
            td.append(btnview);

            tr.append(td);
            target.append(tr);
        });
    }

    function LoadData(page) {
        debugger;
        var numberinpage = 5;
        var keyword = $("#<%=txtTimKiem.ClientID%>").val();
        var dataagr = JSON.stringify({
            keyword: keyword,
            currentpage: parseInt(page),
            numberinpage: numberinpage
        });
        LoadDataWithPaging($("#tableListIntro > tbody"), $("#divpaging"), page, "POST", "/MainSys/ProcessAJAX/AjaxIntroduce.aspx/GetListIntro", dataagr, LoadListIntro, numberinpage, LoadData);
    }





    $(document).ready(function () {
        debugger;
        LoadData(1);
        $("#<%=btnThem.ClientID%>").click(function () {
            location.href = "/MainSys/Manager/Introduces/AddNewIntro.aspx";
        });
        $("#btnShow").click(function () {
            $("#<%=txtTimKiem.ClientID%>").val("");
            LoadData(1);
        });

        $("#btnDelete").click(function () {
            var listcheckbox = $('input[checktype="selectarticle"]:checked');
            if (listcheckbox.length == 0) {
                alertbox("Vui lòng chọn bài viết muốn xóa");
                return;
            }
            confirm("Confirm", "Bạn có muốn xóa những bài viết đã chọn", "OK", "Cancel", function () {
                var listid = [];
                for (var i = 0; i < listcheckbox.length; i++) {
                    var dataid = $(listcheckbox[i]).attr("dataid");
                    listid.push(dataid);
                }
                CallAjaxAspx("POST", "XoaBai", "/MainSys/ProcessAJAX/AjaxIntroduce.aspx", { listid: listid }, function (data) {
                    debugger;
                    var responseDel = JSON.parse(data);
                    if (responseDel.Status) {
                        debugger;
                        alertSmallBox("Xóa bài viết thành công", "1 giây trước...");
                        LoadData(1);
                    }
                    else {
                        alertSmallBox("Xóa bài viết thất bại", "1 giây trước...", "error");
                    }
                }, AjaxLoading(true), AjaxLoading(false));

            });
        });


        $('#ckbCheckAll').click(function () {
            var listcheckbox = $('input[checktype="selectarticle"]');
            for (var i = 0; i < listcheckbox.length; i++) {
                listcheckbox[i].checked = this.checked;
            }
        });

    });

</script>
<section id="widget-grid" class="">
    <div class="row">
        <article class="col-sm-12 col-md-12 col-lg-12">

            <div class="alert alert-info alert-block">
                <h4 class="alert-heading" style="font-weight: bold">QUẢN LÝ BÀI GIỚI THIỆU CHO :
        <label runat="server" id="lbOrg" style="font-weight: bold; display: inline;"></label>
                </h4>
            </div>

            <div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-1" data-widget-editbutton="false" data-widget-fullscreenbutton="false">
                <header>
                    <h2>QUẢN LÝ BÀI VIẾT GIỚI THIỆU</h2>
                    <div class="widget-toolbar">
                        <div class="btn-group">
                            <input class="btn btnthem dropdown-toggle btn-xs btn-success" type="button" id="btnThem" runat="server" style="margin-right: 10px;" value="Add new" />
                            <input type="button" value="Show" class="btn btnthem dropdown-toggle btn-xs btn-success" id="btnShow" />
                        </div>
                    </div>
                </header>

                <div class="widget-body widget-hide-overflow padding">
                    <div class="col-xs-12 col-sm-6">
                        <div id="datatable_tabletools_filter" class="dataTables_filter">
                            <label style="float: left">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                <input type="search" class="form-control" placeholder="input keyword" id="txtTimKiem" runat="server" />
                                <input type="button" onclick="LoadData(1);" value="Search" class="btn btn-default" style="width: 80px;" />
                                <input type="button" id="btnDelete" value="Delete" class="btn btn-default" style="width: 80px;" />
                            </label>
                        </div>
                    </div>

                    <div class="col-sm-12 smart-form">
                        <table id="tableListIntro" class="table table-bordered">
                            <thead>
                                <tr>
                                    <td style="width: 50px;">
                                        <label class="checkbox" style="margin-top: 0px; padding-top: 0px;">
                                            <input type="checkbox" name="checkbox" id="ckbCheckAll">
                                            <i></i>
                                        </label>
                                    </td>
                                    <td>Tiêu đề
                                    </td>
                                    <td style="width: 120px;">Action
                                    </td>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                        <div id="divpaging"></div>
                    </div>
                </div>
            </div>
        </article>
    </div>
</section>
